package com.up.management.controller;

import com.up.common.annotation.Log;
import com.up.common.core.controller.BaseController;
import com.up.common.core.domain.AjaxResult;
import com.up.common.core.page.TableDataInfo;
import com.up.common.enums.BusinessType;
import com.up.common.utils.poi.ExcelUtil;
import com.up.management.domain.entity.ItemCategory;
import com.up.management.domain.vo.ItemCategoryVO;
import com.up.management.service.IItemCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

;

/**
 * 分类管理Controller
 * 
 * @author cloud
 * @date 2025-09-20
 */
@RestController
@RequestMapping("/management/ItemCategory")
public class ItemCategoryController extends BaseController
{
    @Autowired
    private IItemCategoryService itemCategoryService;

    /**
     * 查询分类管理列表
     */
    @PreAuthorize("@ss.hasPermi('management:ItemCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(ItemCategory itemCategory)
    {
        startPage();
        List<ItemCategoryVO> list = itemCategoryService.selectItemCategoryVOList(itemCategory);
        return getDataTable(list);
    }

    /**
     * 导出分类管理列表
     */
    @PreAuthorize("@ss.hasPermi('management:ItemCategory:export')")
    @Log(title = "分类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ItemCategory itemCategory)
    {
        List<ItemCategory> list = itemCategoryService.selectItemCategoryList(itemCategory);
        ExcelUtil<ItemCategory> util = new ExcelUtil<ItemCategory>(ItemCategory.class);
        util.exportExcel(response, list, "分类管理数据");
    }

    /**
     * 获取分类管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('management:ItemCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(itemCategoryService.selectItemCategoryVOById(id));
    }

    /**
     * 新增分类管理
     */
    @PreAuthorize("@ss.hasPermi('management:ItemCategory:add')")
    @Log(title = "分类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ItemCategory itemCategory)
    {
        return toAjax(itemCategoryService.insertItemCategory(itemCategory));
    }

    /**
     * 修改分类管理
     */
    @PreAuthorize("@ss.hasPermi('management:ItemCategory:edit')")
    @Log(title = "分类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ItemCategory itemCategory)
    {
        return toAjax(itemCategoryService.updateItemCategory(itemCategory));
    }

    /**
     * 删除分类管理
     */
    @PreAuthorize("@ss.hasPermi('management:ItemCategory:remove')")
    @Log(title = "分类管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(itemCategoryService.deleteItemCategoryByIds(ids));
    }
}
